home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 10
/
010.d81
/
dos #27
< prev
next >
Wrap
Text File
|
2022-08-26
|
4KB
|
204 lines
DOS and don'ts -- Part 27
by Jimmy Weiler
Now we'll discuss some special
techniques. Up to now in our
discussion of RELative files we have
assumed that you would want to read an
entire record, start to finish,
whenever you accessed the file. It is
possible that you would only want to
read one of many fields inside any
particular record.
This wouldn't gain you much in a
file with only two fields per record,
but if you stored first name, last
name, phone number, street address,
city, state, zip code, social security
number, weight, hair color, driver's
license number, and shoe size in each
record, it could mean a 95% time
savings every time you checked
somebody's shoe size.
Here's how:
Decide in advance how big each field
is allowed to be -- remember to allow
space for the carriage returns. Then
add up the fields' lengths to find out
where in each record to write that
information. A RELative file accessed
normally, with one INPUT# after
another is like a bunch of little
SEQ files. A RELative file accessed
this way is like a bunch of little
REL files.
Field name Length Position
--------------------------------------
First name = 12 1
Last name = 12 13
Phone number = 17 25
Street address = 28 44
City = 18 72
State = 3 90
Zip code = 6 93
S/S/N = 10 99
weight = 4 109
Hair color = 8 114
Driver's lic. = 12 122
Shoe size = 7 134
-------------------------------------
TOTAL 141
A single record would look like this:
--------------------------------------
<first name><last name ><-phone number
---><----street address--------><city-
----------->st.<zip ><ssn----->wgt.<--
hair><-driver's-><shoe->
--------------------------------------
And typical data might be:
--------------------------------------
Jimmy/ Weiler/ (318)868-7247/
4025 Greenway Rd./ Shreve
port/ LA/71130/123500292/180/bla
ck/ 6069023/ 10 1/2/
--------------------------------------
Every time you wanted to read from
or write to the file, you would
precede your INPUT# or PRINT# with
a POSITION command to the appropriate
character in the record.
Here's the code that you would need
to write an entire record:
10 OPEN 15,8,15
20 OPEN 3,8,4,"INFOFILE,L,"+CHR$(141)
30 INPUT"Read what record?";R
40 HB=INT(R/256):LB=R-(HB*256)
50 P$="P"+CHR$(4)+CHR$(LB)+CHR$(HB)
60 PRINT#15,P$CHR$(1)
70 PRINT#3,FIRST$
80 PRINT#15,P$CHR$(13)
90 PRINT#3,LAST$
100 PRINT#15,P$CHR$(25)
110 PRINT#3,PHNE$
120 PRINT#15,P$CHR$(44)
130 PRINT#3,ADDRESS$
140 PRINT#15,P$CHR$(72)
150 PRINT#3,CITY$
160 PRINT#15,P$CHR$(90)
170 PRINT#3,S$
180 PRINT#15,P$CHR$(93)
190 PRINT#3,ZIP$
200 PRINT#15,P$CHR$(99)
210 PRINT#3,SSN$
220 PRINT#15,P$CHR$(109)
230 PRINT#3,WT$
240 PRINT#15,P$CHR$(114)
250 PRINT#3,HAIR$
260 PRINT#15,P$CHR$(122)
270 PRINT#3,DL$
280 PRINT#15,P$CHR$(134)
290 PRINT#3,SHOE$
That's quite a bit of work for your
Commodore to have to do, but it's
worth it. Now, if you want someone's
shoe size you don't need:
295PRINT#15,"P"CHR$(3)CHR$(LB)CHR$(HB)
CHR$(1)
300 INPUT#3,X$,X$,X$,X$,X$,X$,X$,X$,
X$,X$,X$,SHOE$
(All those X$'S are throw-away
strings. They are just there to
accept INPUT from all the fields
that don't interest us.)
All you need to do is position to the
byte of the Shoe Size field and do
a single INPUT#
310PRINT#15,"P"CHR$(3)CHR$(LB)CHR$(HB)
CHR$(134)
320INPUT#3,SHOE$
That's a savings of 11 INPUT#'s.
Remember, INPUT from and OUTPUT to
the 1541 drive is slow, compared to
how fast your Commodore can handle
data. Any technique that can get
pertinent data from the disk drive
with fewer INPUT#'s will make your
program appear to run faster, and
ultimately, frustrate the user less.
--------- <end of article> -----------